﻿namespace WriterStars.Data.Repository
{
    using System;
    using System.Linq;
    using WriterStars.Model;

    public class ContestRepository : GenericRepository<Contest>, IContestRepository
    {
        public ContestRepository()
            : base(new WriterStarsDbContext())
        {
        }

        public ContestRepository(IWriterStarsDbContext db)
            : base(db)
        {
        }

        public IQueryable<Contest> ActiveContests()
        {
            var activeContests = this.GetIncluding(x => x.ContestBooks).Where(x => x.StartDate < DateTime.Now && DateTime.Now < x.EndDate);
            return activeContests;
        }

        public IQueryable<Contest> UpcomingContests()
        {
            var upcomingContests = this.GetIncluding(x => x.ContestBooks).Where(x => x.StartDate > DateTime.Now);
            return upcomingContests;
        }
    }
}